package com.zoke.daycarpool.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.zoke.daycarpool.R;
import com.zoke.daycarpool.base.BaseUi;
import com.zoke.daycarpool.util.LogTest;

/**
 * 筛选
 * 
 * @author JackWu
 * @version
 * @date 2015-1-7
 * @_QQ_ 651319154
 */
public class Filtrate extends BaseUi implements OnClickListener {
	private TextView mMdAllTv;
	private TextView mMdToTv;
	private TextView mMdComeTv;
	private TextView mDisAllTv;
	private TextView mDis1kmTv;
	private TextView mDis2kmTv;
	private TextView mTimeAllTv;
	private TextView mTimeTodayTv;
	private TextView mTimeTomoTv;
	/** 过滤器结果 **/
	public static final int filtrateResult = 33;
	/** 去北京 **/
	public static final String KeyToBJ = "_iskeybj";
	/** 距离 **/
	public static final String keyDest = "_keyDest";
	/** 时间 **/
	public static final String keyDay = "_keyDay";

	private int mToBj = 0;
	private int mDest = 0;
	private int mDay = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_filtrate);
		mTitleManager.setTitle("筛选");
		mTitleManager.setLeftIcon(R.drawable.title_back);
		mEnableSwipeRight = true;
		mToBj = getIntent().getIntExtra(KeyToBJ, 0);
		mDest = getIntent().getIntExtra(keyDest, 0);
		mDay = getIntent().getIntExtra(keyDay, 0);
		LogTest.tag(mToBj + ";" + mDest + ";" + mDay);
		findView();
		doEvent();
		// --
		checkMdSelected(mToBj);
		checkDisSelected(mDest);
		checkTimeSelected(mDay);
	}

	@Override
	protected void findView() {
		// 出发to from
		mMdAllTv = (TextView) findViewById(R.id.filter_mdall_tv);
		mMdToTv = (TextView) findViewById(R.id.filter_mdto_tv);
		mMdComeTv = (TextView) findViewById(R.id.filter_mdcome_tv);

		// 出发距离
		mDisAllTv = (TextView) findViewById(R.id.filter_disall_tv);
		mDis1kmTv = (TextView) findViewById(R.id.filter_dis1km_tv);
		mDis2kmTv = (TextView) findViewById(R.id.filter_dis2km_tv);

		// 出发时间
		mTimeAllTv = (TextView) findViewById(R.id.filter_timeall_tv);
		mTimeTodayTv = (TextView) findViewById(R.id.filter_timetoday_tv);
		mTimeTomoTv = (TextView) findViewById(R.id.filter_timetomo_tv);

	}

	@Override
	protected void doEvent() {
		mMdAllTv.setOnClickListener(this);
		mMdToTv.setOnClickListener(this);
		mMdComeTv.setOnClickListener(this);

		mDisAllTv.setOnClickListener(this);
		mDis1kmTv.setOnClickListener(this);
		mDis2kmTv.setOnClickListener(this);

		mTimeAllTv.setOnClickListener(this);
		mTimeTodayTv.setOnClickListener(this);
		mTimeTomoTv.setOnClickListener(this);
	}

	/** 根据点击位置 来判断选中色 **/
	private void checkMdSelected(int position) {
		mToBj = position;
		mMdAllTv.setSelected(position == 0 ? true : false);
		mMdToTv.setSelected(position == 1 ? true : false);
		mMdComeTv.setSelected(position == 2 ? true : false);

	}

	/** 根据出发地点来判断选择色 **/
	private void checkDisSelected(int position) {
		mDest = position;
		mDisAllTv.setSelected(position == 0 ? true : false);
		mDis1kmTv.setSelected(position == 1 ? true : false);
		mDis2kmTv.setSelected(position == 2 ? true : false);
	}

	private void checkTimeSelected(int position) {
		mDay = position;
		mTimeAllTv.setSelected(position == 0 ? true : false);
		mTimeTodayTv.setSelected(position == 1 ? true : false);
		mTimeTomoTv.setSelected(position == 2 ? true : false);
	}

	/** 确认按钮 **/
	public void onClickDell(View view) {
		Intent intent = new Intent();
		intent.putExtra(KeyToBJ, mToBj);
		intent.putExtra(keyDest, mDest);
		intent.putExtra(keyDay, mDay);
		setResult(filtrateResult, intent);
		Filtrate.this.onBackPressed();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		// 目的地
		case R.id.filter_mdall_tv:
			checkMdSelected(0);
			break;
		case R.id.filter_mdto_tv:
			checkMdSelected(1);
			break;
		case R.id.filter_mdcome_tv:
			checkMdSelected(2);
			break;
		// 出发地点
		case R.id.filter_disall_tv:
			checkDisSelected(0);
			break;

		case R.id.filter_dis1km_tv:
			checkDisSelected(1);
			break;
		case R.id.filter_dis2km_tv:
			checkDisSelected(2);
			break;
		// 出发时间
		case R.id.filter_timeall_tv:
			checkTimeSelected(0);
			break;

		case R.id.filter_timetoday_tv:
			checkTimeSelected(1);
			break;
		case R.id.filter_timetomo_tv:
			checkTimeSelected(2);
			break;

		default:
			break;
		}
	}
}
